<!--- 简历上传 -->
<template>
  <div class="attendance-container">
    <HPCommonPage :titleText="'成本管理 / 考勤管理'">
      <template v-slot:searchForm>
        <el-form
          :inline="true"
          :model="selectData"
          class="form-box res-form-box"
        >
          <el-form-item label="员工编号：">
            <el-input
              v-model="selectData.workCode"
              clearable
              placeholder="请输入员工编号"
            ></el-input>
          </el-form-item>
          <el-form-item label="姓名：">
            <el-input
              v-model="selectData.userName"
              clearable
              placeholder="请输入输入姓名"
            ></el-input>
          </el-form-item>
          <!-- <el-form-item label="供应商名称：">
            <el-select
              v-model="selectData.supplierId"
              clearable
              :filterable="true"
              :remote="true"
              :remote-method="findAdmitSupplier"
              placeholder="请输入部门"
            >
              <el-option
                v-for="(optionItem, index) in deptOptions"
                :key="index"
                :label="optionItem['label']"
                :value="optionItem['coded']"
              ></el-option>
            </el-select>
          </el-form-item> -->
          <el-form-item label="部门：">
            <el-input
              v-model="selectData.deptName"
              clearable
              placeholder="请输入部门名称"
            ></el-input>
          </el-form-item>
          <el-form-item label="月份：" :class="'date-font-item'">
            <el-date-picker
              v-model="selectData.date"
              size="small"
              value-format="yyyy-MM"
              type="monthrange"
              range-separator="至"
              start-placeholder="开始月份"
              end-placeholder="结束月份"
            >
            </el-date-picker>
          </el-form-item>
        </el-form>
      </template>
      <template v-slot:searchFormbtn>
        <el-button type="success" size="small" @click="onSearch"
          >查询</el-button
        >
      </template>
      <template v-slot:table>
        <HPTable
          :tableHeaderItems="tableHeaderItems"
          :tableData="tableData"
          :loading="isLoad"
        >
        </HPTable>
      </template>
      <template v-slot:pagination>
        <el-pagination
          v-if="totals"
          @size-change="handleSizeChange"
          @current-change="handleCurrentChange"
          :current-page="selectData.pageNum"
          :page-sizes="[10, 20, 30, 40, 50]"
          :page-size="selectData.pageSize"
          background
          layout="total, sizes, prev, pager, next, jumper"
          :total="totals"
        >
        </el-pagination>
      </template>
    </HPCommonPage>
    <el-dialog
      title="考勤详情"
      :visible.sync="detailVisiable"
      :custom-class="'hours-dialog'"
      width="1250px"
    >
      <HPTable
        :tableHeaderItems="detailTableHeaderItems"
        :tableData="detailTableData"
        :loading="loading"
        height="500px"
      />
    </el-dialog>
  </div>
</template>
<script>
import HPCommonPage from "@/components/HPCommonPage";
import HPTable from "@/components/HPTable";
import {
  attendanceTableColumn,
  attendanceDetailTableColumn,
} from "../js/column";
import {
  fetchManHourDetail,
  getAttendanceDetails,
  findBilibiliSupplierList,
} from "@/fetch/modules/attendance";
export default {
  components: {
    HPCommonPage,
    HPTable,
  },
  data() {
    return {
      selectData: {
        // 查询条件对象
        workCode: "", // 外包人员编号
        userName: "", // 状态
        deptName: "", // 部门ID
        supplierCode: "", // 外包人员名称
        date: "", // 开始日期
        endDate: "", // 岗位名称
        pageNum: "", // 当前页
        pageSize: "", // 每页条数
        pageNum: 1,
        pageSize: 10,
      },
      tableHeaderItems: attendanceTableColumn, // table字段
      tableData: [], // table数据
      totals: 0, // 总条数
      isLoad: true,
      detailTableData: [],
      detailTableHeaderItems: attendanceDetailTableColumn,
      loading: false,
      detailVisiable: false,
    };
  },
  created() {
    this.loadTableLists();
  },
  methods: {
    findAdmitSupplier(val) {
      findBilibiliSupplierList().then((res) => {
        console.log(res);
      });
    },
    // * 获取table数据
    loadTableLists() {
      this.isLoad = true;
      const params = {
        ...this.selectData,
        beginDate: this.selectData.date && this.selectData.date[0],
        endDate: this.selectData.date && this.selectData.date[1],
      };
      fetchManHourDetail(params).then((res) => {
        const data = res.data;
        // console.log(data)
        if (data.state === "0000") {
          const { pageNum, lastPage } = data.data;
          this.tableData = data.data.list;
          this.totals = data.data.total;
          this.isLoad = false;
          if(pageNum > lastPage && lastPage > 0) {
            this.selectData.pageNum = lastPage
            this.loadTableLists()
          }
        }
      });
    },
    onLookDetail(row) {
      const params = {
        workCode: row.workCode,
        attendanceDate: row.attendanceDate,
      };
      getAttendanceDetails(params).then((res) => {
        const data = res.data;
        if (data.state === "0000") {
          this.detailTableData = data.data;
          this.detailVisiable = true;
        }
      });
    },
    // * 查询
    onSearch() {
      this.selectData.pageNum = 1;
      this.loadTableLists();
    },
    // * 查看
    lookResumeDetail({ needsId, state }) {},
    // * 切换页条数
    handleSizeChange(val) {
      this.selectData.pageSize = val;
      this.selectData.pageNum = 1;
      this.loadTableLists();
    },
    // * 切换页数
    handleCurrentChange(val) {
      this.selectData.pageNum = val;
      this.loadTableLists();
    },
  },
};
</script>
<style lang="scss">
.attendance-container {
  height: 100%;
}
</style>
